package com.atguigu.gmall.gateway.config;

import com.atguigu.gmall.gateway.properties.FilterProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @author 钟涛
 * @version 1.0
 * @description: TODO
 * @date 2021/12/6 21:23
 */
@Configuration
@EnableConfigurationProperties(FilterProperties.class)
public class CorsConfig {
//    @Bean  //解决跨域请求的过滤类
//    public CorsWebFilter corsWebFilter(){
//
//        // cors跨域配置对象
//        CorsConfiguration configuration = new CorsConfiguration();
//        configuration.addAllowedOrigin("*"); //设置允许访问的网络
//        configuration.setAllowCredentials(true); // 设置是否从服务器获取cookie
//        configuration.addAllowedMethod("*"); // 设置请求方法 * 表示任意
//        configuration.addAllowedHeader("*"); // 所有请求头信息 * 表示任意
//
//        // 配置源对象
//        UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource();
//        configurationSource.registerCorsConfiguration("/**", configuration);
//        // cors过滤器对象
//        return new CorsWebFilter(configurationSource);
//    }
}
